package com.lovo.user.mq;

import com.lovo.common.bean.UserInfoBean;
import com.lovo.user.service.IUserInfoService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

@Component
@RabbitListener(queues = {"register.direct.queue"})
public class RegisterReceiver {
    @Resource
    private IUserInfoService userInfoService;
    @RabbitHandler
    public void reveive(UserInfoBean userInfoBean, Message message, Channel channel){
        userInfoService.sendMail(userInfoBean.getUserEmail());
        userInfoService.sendMessage(userInfoBean.getUserPhone());
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
